package fr.utbm.to52.android_bibtex.main;

import java.util.Arrays;
import java.util.Comparator;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import fr.utbm.to52.android_bibtex.R;
import fr.utbm.to52.android_bibtex.controller.AddEntryController;
import fr.utbm.to52.android_bibtex.model.spec.EntryDefinition;
import fr.utbm.to52.android_bibtex.model.spec.EntryDefinitions;

public class AddEntryActivity extends Activity {

	private Button nextButton;
	private AddEntryController controller;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_entry);
		this.controller = new AddEntryController(this);
		this.nextButton = (Button)findViewById(R.id.buttonNext);
		this.nextButton.setOnClickListener(this.controller);
		setEntriesView();
	}

	public void setEntriesView() {
		Spinner spinner = (Spinner) findViewById(R.id.spinner);
		EntryDefinition[] array = EntryDefinitions.getInstance().getDefinitions().values().toArray(new EntryDefinition[0]);
		Arrays.sort(array, new Comparator<EntryDefinition>() {
			@Override
			public int compare(EntryDefinition lhs, EntryDefinition rhs) {
				return lhs.getName().compareTo(rhs.getName());
			}
		});
		ArrayAdapter<EntryDefinition> adapter = new ArrayAdapter<EntryDefinition>(this, android.R.layout.simple_spinner_dropdown_item, array);
		spinner.setAdapter(adapter);
	}

	public Button getNextButton() {
		return this.nextButton;
	}

	public AddEntryController getController() {
		return this.controller;
	}

}
